/*
 * 2005-11-17 lxm 创建。
 */
package com.hd123.rumba.domain;

import java.text.ParseException;

import net.sf.hibernate.HibernateException;

import com.hd123.rumba.exception.BusinessException;
import com.hd123.rumba.runtime.DVersionedPersistent;
import com.hd123.rumba.runtime.IPersistent;
import com.hd123.rumba.runtime.NamingMgr;

/**
 * @author lxm
 * 
 * IDomain对应的数据交换对象
 *
 */
public class DDomain extends DVersionedPersistent {

  private String domainUuid;
  private String lastModifier;
  private String state;
  private String code;
  private String name;
  private String upperDomainUuid;

  // /////////////////////////
  // 用于 Web Service 数据交换
  
  public static DDomain create(IDomain source) {
    if (source == null)
      return null;
    else {
      DDomain result = new DDomain();
      result.assignFrom(source);
      return result;
    }
  }

  /**
   * 从指定的接口对象赋值。
   * 
   * @param source
   */
  public void assignFrom(IPersistent source) {
    super.assignFrom(source);
    if (source instanceof IDomain) {
      this.domainUuid = exportString(source, new String[] {"getDomain", "getUuid"});
      this.lastModifier = exportString(source, "getLastModifier");
      this.state = exportInteger(source, "getState");
      this.code = exportString(source, "getCode");
      this.name = exportString(source, "getName");
      this.upperDomainUuid = exportString(source, new String[] {"getUpperDomain", "getUuid"});
    }
  }

  /**
   * 将数据赋值给指定的接口对象。
   * 
   * @param source
   */
  public void assignTo(IPersistent target) throws ParseException, BusinessException, HibernateException {
    super.assignTo(target);
    if (target instanceof IDomain) {
      setPropValue(target, "setDomain", importDomain(this.domainUuid));
      importString(target, "setLastModifier", this.lastModifier);
      importInteger(target, "setState", this.state);
      importString(target, "setCode", this.code);
      importString(target, "setName", this.name);
      setPropValue(target, "setUpperDomain", importDomain(this.upperDomainUuid));
    }
  }
  
  /**
   * 导入Domain，根据domainUuid取得Domain。<br>
   * 
   * @param domainUuid
   * @return
   * @throws BusinessException
   *           若没有找到，则报错。
   * @throws HibernateException
   */
  public static IDomain importDomain(String domainUuid) throws BusinessException,
      HibernateException {
    if (domainUuid == null || domainUuid.equals(new String("")))
      return null;
    IDomain domain = ((IDomainMgr) NamingMgr.getInstance().lookupMgr(IDomainMgr.class))
        .getDomain(domainUuid);
    if (domain == null)
      throw new BusinessException("系统中不存在指定的域(uuid=" + domainUuid + ")。");
    return domain;
  }

  // /////////////////////////
  // 属性方法
  
  public String getCode() {
    return code;
  }
  public void setCode(String code) {
    this.code = code;
  }
  public String getDomainUuid() {
    return domainUuid;
  }
  public void setDomainUuid(String domainUuid) {
    this.domainUuid = domainUuid;
  }
  public String getLastModifier() {
    return lastModifier;
  }
  public void setLastModifier(String lastModifier) {
    this.lastModifier = lastModifier;
  }
  public String getName() {
    return name;
  }
  public void setName(String name) {
    this.name = name;
  }
  public String getState() {
    return state;
  }
  public void setState(String state) {
    this.state = state;
  }
  public String getUpperDomainUuid() {
    return upperDomainUuid;
  }
  public void setUpperDomainUuid(String upperDomainUuid) {
    this.upperDomainUuid = upperDomainUuid;
  }
 
  
}
